﻿using Caliburn.Micro;
using myapp.Databases.DAO;
using myapp.Events;
using myapp.Events.ViewModel;
using myapp.Instances;
using myapp.ViewModels;
using myappcore.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace myapp.ViewModels
{
    /// <summary>
    /// Function List ViewModel
    /// </summary>
    public class FunctionListViewModel : IBaseContentViewModel, IHandle<ViewModelFunctionGroupSelectedEvent>
    {
        #region Attribute

        private static FunctionListViewModel _instance;

        private IObservableCollection<FunctionViewModel> _functionViewModelList;
        #endregion

        #region Properties

        /// <summary>
        /// Group of possition
        /// </summary>
        public FunctionGroup FunctionGroup { get; set; }

        /// <summary>
        /// Is Show List Function
        /// </summary>
        public bool IsShow { get; set; }
        /// <summary>
        /// List Function of Group
        /// </summary>
        public IObservableCollection<FunctionViewModel> FunctionViewModelList
        {
            get
            {
                return _functionViewModelList;
            }
            set
            {
                if (null != value)
                {
                    _functionViewModelList = value;
                    NotifyOfPropertyChange(() => FunctionViewModelList);
                }
            }
        }

        public static FunctionListViewModel Instance
        {
            get
            {
                if (null == _instance)
                {
                    _instance = new FunctionListViewModel();
                    _instance.IsChanged = true;
                }
                return _instance;
            }
        }

        #endregion
        public FunctionListViewModel()
        {
            MainInstance.Instance.EventAggregator.Subscribe(this);
            DisplayName = "Chức Năng";
            CurrentColor = MainInstance.Instance.ColorConfig.FunctionNormal;
            FunctionViewModelList = new BindableCollection<FunctionViewModel>();
        }
        #region Constructure


        #endregion

        #region Method

        public void Handle(ViewModelFunctionGroupSelectedEvent message)
        {
            if (null != message && null != message.FunctionGroupViewModel)
            {
                FunctionGroup = message.FunctionGroupViewModel.FunctionGroup;
                FunctionViewModelList = message.FunctionGroupViewModel.FunctionViewModelList;
                IsShow = true;
                MainInstance.Instance.EventAggregator.Publish(new ViewModelFunctionListShowEvent() { IsShow = true });
            }
        }
        #endregion




    }
}
